<?php
namespace app\admin\controller;
use think\Db;
class User extends Base
{
    //列表
    public function lists(){
        if(is_post()){
            $d = request()->post();
            $map = [];
            if($d['keyword']!=''){
                $map[] = ['username|phone','like',"%{$d['keyword']}%"];
            }
        	$rs = model('User')::where($map)
                                ->order('id desc')
                                ->paginate($d['limit'],false,['page'=>$d['page']]);
            if($rs){
                $rs = $rs->toArray();
                return suc($rs['data'], $rs['total']);
            }else{
                return suc([],0);
            }
        }
        return $this->fetch('');
    }

    //编辑
    public function edit($id=''){
        if(is_post()){
            $d = request()->post();
            if(model('Article')->renew($d)){
                session('js.function','preload');
                return suc();
            }else{
                return err(model('Article')->getError());
            }
        }
        $catlist = model('ArticleCat')::allSubCat();
        $reclist = model('ArticleRec')::column('title','id');
        $info = model('Article')::get($id);
        return $this->fetch('',['info'=>$info,'catlist'=>$catlist,'reclist'=>$reclist]);
    }
    
    //详情
    public function detail($id){
        return $this->fetch();
    }
}
